from manim import *
class math(MovingCameraScene):
    def construct(self):
        self.camera.background_color = BLACK  # 设置背景颜色
        self.camera.frame_width = 100  # 设置边框宽度
        self.camera.frame_height = 60  # 设置边框高度
        self.camera.pixel_height = 1080  # 设置像素高度
        self.camera.pixel_width = 1920  # 设置像素宽度
        self.camera.center = ORIGIN  # 设置中心点位置
        self.camera.scale_factor = 1.0  # 设置缩放因子
        #设置横线
        for i in range(60*2+1):       
            dot1=Dot([-500,5*(i-60),0]).set_opacity(0.5)
            dot2=Dot([500,5*(i-60),0]).set_opacity(0.5)
            if i==6:
                line1=Line(dot1,dot2).set_color(WHITE).set_opacity(0.5)
                
            else:
                line1=Line(dot1,dot2).set_color(WHITE).set_opacity(0.5)
               
            self.add(dot1,dot2,line1)
        #设置竖线
        for i in range(100*2+1):        
            dot3=Dot([(i-100)*5,-300,0]).set_opacity(0.5)
            dot4=Dot([(i-100)*5,300,0]).set_opacity(0.5)
            if i==10:
                line2=Line(dot3,dot4).set_color(WHITE).set_opacity(0.5)
                
            else:
                line2=Line(dot3,dot4).set_color(WHITE).set_opacity(0.5)
            self.add(dot3,dot4,line2)
        #设置三个点
        dot1 = Dot(radius=1, color=RED)  
        dot1.move_to([-47.5,27.5,0]) 
        dot2 = Dot(radius=1, color=YELLOW)  
        dot2.move_to([-42.5,27.5,0])  
        dot3 = Dot(radius=1, color=GREEN)  
        dot3.move_to([-37.5,27.5,0])
        #镜头跟进效果 
        self.camera.frame.save_state()
        #题目出现
        text = Tex(
                r"\text{计算}\hspace{0.3em}$\int_{0}^{+\infty} \dfrac{x \ln x}{1 + x^4} \, dx$",  # 0.3em 可自由调整
                tex_template=TexTemplateLibrary.ctex
                    ).scale(5.0).move_to([0, 0, 0])
        long_text2=("思路二：")
        text102 = Text(long_text2,color=YELLOW,
                   font_size=200).move_to([-30, 10, 0])
       
        self.wait(0.2)
        self.play(Write(text),Write(text102),self.camera.frame.animate.scale(0.8))
        self.wait()
        #镜头拉回
          #分析文本
        #text100=MarkupText("<b><i>分析/解：</i></b>",color=PINK).scale(5.0).move_to([-38,12.5,0])
        self.play(Restore(self.camera.frame))
        self.play(FadeIn(dot1),run_time=0.1)
        self.play(FadeIn(dot2),run_time=0.1)
        self.play(FadeIn(dot3),run_time=0.1)
        #题目向上移动
        self.play(text.animate().move_to([0,20,0]) )
        #镜头拉近
        text1 = Tex(
                r"\hspace{0.3em}$\dfrac{1}{2}\cdot \int_{0}^{+\infty} \dfrac{ \ln x}{1 + x^4} \, dx^2$",  # 0.3em 可自由调整
                tex_template=TexTemplateLibrary.ctex
                    ).scale(5.0).move_to([0, 11, 0])
        
        self.play(Write(text1))
        text2 = Tex(
                r"\hspace{0.3em}$\dfrac{1}{2}\cdot \int_{0}^{+\infty} \dfrac{ \ln x}{1 + \left( x^{2}\right) ^{2}} \, dx^2$",  # 0.3em 可自由调整
                tex_template=TexTemplateLibrary.ctex
                    ).scale(5.0).move_to([0, 11, 0])
        self.play(ReplacementTransform(text1,text2))
        self.wait(0.2)
        text3 = Tex(
                r"\hspace{0.3em}$x^{2}=t$", color=YELLOW, # 0.3em 可自由调整
                tex_template=TexTemplateLibrary.ctex
                    ).scale(5.0).move_to([0, 2, 0])
        
        self.play(Write(text3))
        text4 = Tex(
                r"\hspace{0.3em}$\dfrac{1}{4}\cdot \int _{0}^{+\infty }\dfrac{\ln t}{1+t^{2}}dt$", color=WHITE, # 0.3em 可自由调整
                tex_template=TexTemplateLibrary.ctex
                    ).scale(5.0).move_to([0, 2, 0])
        self.play(ReplacementTransform(text3,text4))
        self.wait(0.2)
        text5 = Tex(
                r"\text{当}$\int _{0}^{+\infty }$\text{碰到}$1+t^{2}$", color=YELLOW, # 0.3em 可自由调整
                tex_template=TexTemplateLibrary.ctex
                    ).scale(5.0).move_to([0, -7, 0])
        self.play(Write(text5))
        text6 = Tex(
                r"\text{令}$u=\tan t$", color=YELLOW, # 0.3em 可自由调整
                tex_template=TexTemplateLibrary.ctex
                    ).scale(5.0).move_to([0, -7, 0])
        self.play(ReplacementTransform(text5,text6))
        self.wait(0.2)
        text7 = Tex(
                r"$\dfrac{1}{4}\cdot \int _{0}^{\frac{\pi }{2}}\ln \tan udu$", color=WHITE, # 0.3em 可自由调整
                tex_template=TexTemplateLibrary.ctex
                    ).scale(5.0).move_to([0, -7, 0])
        self.play(ReplacementTransform(text6,text7))
        self.wait(0.2)

        rectangle=Rectangle(color=BLUE,fill_opacity=0.3,width=20,height=7
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle.move_to([0, -7, 0])
       
        
        self.play(Create(rectangle))
        self.play(FadeOut(rectangle))
        text8 = Tex(
                r"$\int _{a}^{b}f\left( x\right) dx=\int ^{b}_{a}f\left( a+b-x\right) dx=\dfrac{1}{2}\cdot \int _{a}^{b}\left[ f\left( x\right) +f\left( a+b-x\right) dx\right] $", color=YELLOW, # 0.3em 可自由调整
                tex_template=TexTemplateLibrary.ctex
                    ).scale(5.0).move_to([0, -14, 0])
        self.play(Write(text8))
        text9 = Tex(
                r"$\dfrac{1}{8}\cdot \int _{0}^{\frac{\pi }{2}}\left[ \ln \tan u+\ln \tan \left( \dfrac{\pi }{2}-u\right) \right] du$", color=WHITE, # 0.3em 可自由调整
                tex_template=TexTemplateLibrary.ctex
                    ).scale(5.0).move_to([0, -14, 0])
        self.play(ReplacementTransform(text8,text9))
        self.wait(0.2)
        
        #下划线
        dot1=Dot([3,-18,0])
        dot2=Dot([15,-18,0])
        line=Line(dot1,dot2).set_color(YELLOW)
        line.set_stroke(width=30)  # 设置宽度为 30
        self.play(Create(line))
        text10 = Tex(
                r"$\dfrac{1}{8}\cdot \int _{0}^{\frac{\pi }{2}}\left[ \ln \tan u+\ln \cot u \right] du$", color=WHITE, # 0.3em 可自由调整
                tex_template=TexTemplateLibrary.ctex
                    ).scale(5.0).move_to([0, -14, 0])
        self.play(ReplacementTransform(text9,text10),FadeOut(line))
        self.wait(0.2)
        text11 = Tex(
                r"$\dfrac{1}{8}\cdot \int _{0}^{\frac{\pi }{2}}\left[ \ln \left( \tan u\cdot \cot u\right)  \right] du$", color=WHITE, # 0.3em 可自由调整
                tex_template=TexTemplateLibrary.ctex
                    ).scale(5.0).move_to([0, -14, 0])
        self.play(ReplacementTransform(text10,text11))
        self.wait(0.2)
        text12 = Tex(
                r"$\dfrac{1}{8}\cdot \int _{0}^{\frac{\pi }{2}}\left[ \ln 1  \right] du$", color=WHITE, # 0.3em 可自由调整
                tex_template=TexTemplateLibrary.ctex
                    ).scale(5.0).move_to([0, -14, 0])
        self.play(ReplacementTransform(text11,text12))
        self.wait(0.2)
        rectangle=Rectangle(color=BLUE,fill_opacity=0.3,width=20,height=7
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle.move_to([3, 20, 0])
        text13 = Tex(
                r"$=0$", color=YELLOW, # 0.3em 可自由调整
                tex_template=TexTemplateLibrary.ctex
                    ).scale(5.0).next_to(rectangle,RIGHT,buff=1)
        
        self.play(Create(rectangle),ReplacementTransform(text12,text13))
        self.wait(0.2)
        self.wait()